using System;
using System.Collections.Generic;
using System.Linq;
using Hematology.Data.Interface;

namespace Hematology.Data
{
	public partial class AccessRole : IComparable<AccessRole>, IEquatable<AccessRole>, ISimpleData
	{
		public static AccessRole SearchByName(string roleName)
		{
			return Search(null, roleName, null, false, null, null).FirstOrDefault();
		}

		public static List<AccessRole> GetAllRoles()
		{
			return Search(null, null, null, false, null, null);
		}

		public void Save()
		{
			IsDeleted = false;
			CreateDate = DateTime.Now;
			LastModifiedDate = DateTime.Now;

			Insert();
		}

		public void UpdateInstance()
		{
			LastModifiedDate = DateTime.Now;

			Update();
		}

		public void MarkAsDeleted()
		{
			IsDeleted = true;

			Update();
		}

		public int CompareTo(AccessRole other)
		{
			return Name.CompareTo(other.Name);
		}

		public bool Equals(AccessRole other)
		{
			return RoleId.Equals(other.RoleId) && Name.Equals(other.Name) && Description.Equals(other.Description) &&
				   CreateDate.Equals(other.CreateDate) && IsDeleted.Equals(other.IsDeleted) &&
				   LastModifiedDate.Equals(other.LastModifiedDate);
		}
	}
}

